package com.fw.service.impl;

import java.util.List;

import com.fw.dao.OrderDao;
import com.fw.dao.impl.OrderDaoImpl;
import com.fw.model.Ecommerce;
import com.fw.model.Order;
import com.fw.model.User;
import com.fw.service.OrderService;

public class OrderServiceImpl implements OrderService {
	OrderDao orderDao = null;
	@Override
	public boolean add_orderDao(Order order) {
		orderDao = new OrderDaoImpl();
		return orderDao.add_orderDao(order);
	}

	@Override
	public boolean update_orderByIdDao(Order order) {
		orderDao = new OrderDaoImpl();
		return orderDao.update_orderByIdDao(order);
	}

	@Override
	public boolean delete_orderByIdDao(Order order) {
		orderDao = new OrderDaoImpl();
		return orderDao.delete_orderByIdDao(order);
	}

	@Override
	public Order query_orderByIdDao(Order order) {
		orderDao = new OrderDaoImpl();
		Order o = orderDao.query_orderByIdDao(order);
		if(o!= null){
			User user = o.getUser();
			Ecommerce ec = o.getEcommerce();
			if(user!=null) user.remove("u_pwd");
			o.put("user", user);
			o.put("ecommerce", ec);
		}
		return o;
	}

	@Override
	public Integer query_totalOrderByPageDao(String sql, List<Object> par) {
		orderDao = new OrderDaoImpl();
		return orderDao.query_totalOrderByPageDao(sql, par);
	}

	@Override
	public List<Order> query_allOrderByPageDao(String sql, int firstPage,
			int maxPage, List<Object> par) {
		orderDao = new OrderDaoImpl();
		List<Order> os = orderDao.query_allOrderByPageDao(sql, firstPage, maxPage, par);
		for(int i = 0;i<os.size();i++){
			Order order = os.get(i);
			User user = order.getUser();
			user.remove("u_pwd");
			order.put("user", user);
			Ecommerce ec = order.getEcommerce();
			order.put("ecommerce",ec);
		}
		return os;
	}

}
